/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.model.generic;

import canteen.sys.SessionFactoryClass;
import canteen.sys.model.entity.repository.BillDetailDAO;
import canteen.sys.model.entity.repository.BillDetailDAOImpl;
import canteen.sys.model.entity.repository.BillMasterDAO;
import canteen.sys.model.entity.repository.BillMasterDAOImpl;
import canteen.sys.model.entity.repository.DepartmentMasterDAO;
import canteen.sys.model.entity.repository.DepartmentMasterDAOImpl;
import canteen.sys.model.entity.repository.DesignationMasterDAO;
import canteen.sys.model.entity.repository.DesignationMasterDAOImpl;
import canteen.sys.model.entity.repository.EmployeeMasterDAO;
import canteen.sys.model.entity.repository.EmployeeMasterDAOImpl;
import canteen.sys.model.entity.repository.FeedbackDAO;
import canteen.sys.model.entity.repository.FeedbackDAOImpl;
import canteen.sys.model.entity.repository.ItemMasterDAO;
import canteen.sys.model.entity.repository.ItemMasterDAOImpl;
import canteen.sys.model.entity.repository.ItemTypeMasterDAO;
import canteen.sys.model.entity.repository.ItemTypeMasterDAOImpl;
import canteen.sys.model.entity.repository.LoginDAO;
import canteen.sys.model.entity.repository.LoginDAOImpl;
import canteen.sys.model.entity.repository.SubDepartmentMasterDAO;
import canteen.sys.model.entity.repository.SubDepartmentMasterDAOImpl;
import org.hibernate.HibernateException;
import org.hibernate.Session;

/**
 *
 * @author TNT
 */
public class HibernateDAOFactory extends DAOFactory {

    private HibernateDAOFactory() {
    }

    public static HibernateDAOFactory getInstance() {
        return HibernateDAOFactoryHolder.INSTANCE;
    }

    public Session getCurrentSession() {
        return SessionFactoryClass.getInstance().getSessionFactory().getCurrentSession();
    }

    private GenericHibernateDAOSupport instantiateDAO(Class daoClass) {
        try {
            GenericHibernateDAOSupport dao = (GenericHibernateDAOSupport) daoClass.newInstance();
            dao.setSession(getCurrentSession());
            return dao;
        } catch (InstantiationException | IllegalAccessException | HibernateException ex) {
            throw new RuntimeException("Can not instantiate DAO: " + daoClass, ex);
        }
    }
    
    @Override
    public BillDetailDAO getBillDetailDAO() {
        return (BillDetailDAO) instantiateDAO(BillDetailDAOImpl.class);
    }

    @Override
    public BillMasterDAO getBillMasterDAO() {
        return (BillMasterDAO) instantiateDAO(BillMasterDAOImpl.class);
    }

    @Override
    public DepartmentMasterDAO getDepartmentMasterDAO() {
        return (DepartmentMasterDAO) instantiateDAO(DepartmentMasterDAOImpl.class);
    }

    @Override
    public DesignationMasterDAO getDesignationMasterDAO() {
        return (DesignationMasterDAO) instantiateDAO(DesignationMasterDAOImpl.class);
    }

    @Override
    public EmployeeMasterDAO getEmployeeMasterDAO() {
        return (EmployeeMasterDAO) instantiateDAO(EmployeeMasterDAOImpl.class);
    }

    @Override
    public ItemMasterDAO getItemMasterDAO() {
        return (ItemMasterDAO) instantiateDAO(ItemMasterDAOImpl.class);
    }

    @Override
    public ItemTypeMasterDAO getItemTypeMasterDAO() {
        return (ItemTypeMasterDAO) instantiateDAO(ItemTypeMasterDAOImpl.class);
    }

    @Override
    public LoginDAO getLoginDAO() {
        return (LoginDAO) instantiateDAO(LoginDAOImpl.class);
    }

    @Override
    public SubDepartmentMasterDAO getSubDepartmentMasterDAO() {
        return (SubDepartmentMasterDAO) instantiateDAO(SubDepartmentMasterDAOImpl.class);
    }

    @Override
    public FeedbackDAO getFeedbackDAO() {
        return (FeedbackDAO) instantiateDAO(FeedbackDAOImpl.class);
    }

    private static class HibernateDAOFactoryHolder {

        private static final HibernateDAOFactory INSTANCE = new HibernateDAOFactory();
    }
}
